<template>
  <el-container class="home_container">
    <el-header class="home_header">
      <div class="home_title">家谱系统</div>
      <div class="home_userinfoContainer">
        <el-button @click="logout">退出登录</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside class="home_aside" width="250px">
        <el-menu router style="height: 100%">
          <el-menu-item index="/Home">
            首页
          </el-menu-item>
          <el-menu-item index="/PeopleAdd" :class="$route.path=='/peopleAdd'?'is-active':''">
            添加家谱成员
          </el-menu-item>
          <el-menu-item index="/PeopleManager">
            家谱成员管理
          </el-menu-item>
          <el-menu-item index="/Tree">
            家谱图
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.name }}</el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  methods: {
    // 处理退出登录事件
    logout() {
      let _this = this;
      this.$confirm('注销登录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        localStorage.removeItem('systemAdmin');
        _this.$router.replace({ path: '/' });
      }).catch(() => {});
    }
  },
  data() {
    return {
      admin: ''
    }
  },
  created() {
    /**
     * 在页面加载时从 localStorage 中取出 systemAdmin 属性
     * 使用 JSON.parse 将存储的字符串格式转换回 JSON 格式
     */
    let admin = JSON.parse(window.localStorage.getItem('systemAdmin'));
    this.admin = admin;
  }
}
</script>

<style>
.home_container {
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
}

.home_header {
  background-color: #2B2B2B;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home_title {
  color: #C2C2C2;
  font-size: 22px;
  display: inline;
}

.home_userinfo {
  color: #fff;
  cursor: pointer;
}

.home_userinfoContainer {
  display: inline;
  margin-right: 20px;
}

.home_aside {
  background-color: #FFFFFF;
}
</style>